package com.wingice.system.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wingice.common.page.EntityPageBean;
import com.wingice.common.web.ErrorCodeInfo;
import com.wingice.system.entity.SysOauthClientDetails;
import com.wingice.system.exception.ResultBean;
import com.wingice.system.service.SysOauthClientDetailsService;
import com.wingice.system.validator.sys.oauthclientdetails.SysOauthClientDetailsValidator;
import com.wingice.utils.transfer.TransferUtils;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 客户端信息表 前端控制器
 * </p>
 *
 * @author 胡昊
 * @since 2021-01-13
 */
@RestController
@RequestMapping("/sysOauthClientDetails")
@Tag(name = "第三方客户端管理")
public class SysOauthClientDetailsController {

    @Resource
    private SysOauthClientDetailsService sysOauthClientDetailsService;

    /**
     * @param sysOauthClientDetails 第三方客户端信息
     * @description 新增第三方客户端
     * @author 胡昊
     * @email huhao9277@gmail.com
     * @date 2021/3/10 13:32
     */
    @PreAuthorize("@knifeSecurity.hasPermission('sysOauthClientDetails:insert')")
    @PostMapping("/insert")
    @Operation(summary = "新增第三方客户端")
    public ResultBean<Boolean> insert(@RequestBody SysOauthClientDetails sysOauthClientDetails) {
        SysOauthClientDetailsValidator.insertValidate(sysOauthClientDetails);
        return ResultBean.restResult(sysOauthClientDetailsService.insert(sysOauthClientDetails), ErrorCodeInfo.OK);
    }

    /**
     * @param idList 待删除id列表
     * @description 批量删除第三方客户端
     * @author 胡昊
     * @email huhao9277@gmail.com
     * @date 2021/3/10 13:33
     */
    @PreAuthorize("@knifeSecurity.hasPermission('sysOauthClientDetails:deleteBatch')")
    @DeleteMapping("/deleteBatch")
    @Operation(summary = "批量删除第三方客户端")
    public ResultBean<Boolean> deleteBatch(@RequestBody List<String> idList) {
        SysOauthClientDetailsValidator.deleteValidate(idList);
        return ResultBean.restResult(sysOauthClientDetailsService.removeByIds(idList), ErrorCodeInfo.NO_CONTENT);
    }

    /**
     * @param sysOauthClientDetails 第三方客户端信息
     * @description 修改第三方客户端
     * @author 胡昊
     * @email huhao9277@gmail.com
     * @date 2021/3/10 13:36
     */
    @PreAuthorize("@knifeSecurity.hasPermission('sysOauthClientDetails:update')")
    @PatchMapping("/update")
    @Operation(summary = "修改第三方客户端")
    public ResultBean<Boolean> update(@RequestBody SysOauthClientDetails sysOauthClientDetails) {
        SysOauthClientDetailsValidator.updateValidate(sysOauthClientDetails);
        return ResultBean.restResult(sysOauthClientDetailsService.updateById(sysOauthClientDetails), ErrorCodeInfo.OK);
    }

    /**
     * @param entityPageBean 查询参数
     * @description 分页查询第三方客户端
     * @author 胡昊
     * @email huhao9277@gmail.com
     * @date 2021/3/10 13:37
     */
    @PreAuthorize("@knifeSecurity.hasPermission('sysOauthClientDetails:page')")
    @PostMapping("/page")
    @Operation(summary = "分页查询第三方客户端")
    public ResultBean<Page<SysOauthClientDetails>> page(@RequestBody EntityPageBean<SysOauthClientDetails> entityPageBean) {
        return ResultBean.restResult(sysOauthClientDetailsService.pageSysOauthClientDetails(entityPageBean), ErrorCodeInfo.OK);
    }

    /**
     * @param sysOauthClientDetails clientId和clientSecret信息
     * @description 公钥查询
     * @author 胡昊
     * @email huhao9277@gmail.com
     * @date 2022/4/11 17:32
     */
    @PostMapping("/getSysOauthClientDetailsByClientIdAndSecret")
    @Operation(summary = "公钥查询")
    public ResultBean<String> getSysOauthClientDetailsByClientIdAndSecret(@RequestBody SysOauthClientDetails sysOauthClientDetails) {
        return ResultBean.restResult(sysOauthClientDetailsService.getSysOauthClientDetailsByClientIdAndSecret(sysOauthClientDetails), ErrorCodeInfo.OK);
    }
}

